import wepy from 'wepy';
import api from "@/api/api";
import tip from '@/utils/tip';

let _that;
export default class LoginMixin extends wepy.mixin {
    data = {
        unReadCount:0
    }
    async getUnReadCount(){
        const login_token = await wepy.getStorageSync('login_token');
        if(login_token){
            let res = await api.getUnReadMsgNums({login_token});
            if (res.data.code === 0) {
                _that.unReadCount = res.data.data.unread_count;
            }else{
                tip.toast(res.data.msg);
                _that.unReadCount = 0;
            }
            _that.$apply();
        }
    }

    toMyMessage() {
        if (wepy.getStorageSync('login_token')){
            wepy.navigateTo({
                url: '../pages/myMessageList',
            })
        } else {
            _that.$root.isShowLoginBox();
        }
    }

    methods = {
        
    }

    onShow(){
        _that = this;
    }
}